import {Component, Input, OnInit} from '@angular/core';
import {Gys} from "../../../../model/admin/Gys";
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";

@Component({
  selector: 'app-gysedit',
  templateUrl: './gysedit.component.html',
  styleUrls: ['./gysedit.component.css']
})
export class GyseditComponent implements OnInit {
@Input() optype:string
@Input() id:string
  g:Gys
  lbArray:Array<any>
  constructor(private adminService:AdminService,
              private alertService:AlertService) {
  this.g = new Gys();
  this.lbArray = new Array<any>();
  }

  ngOnInit(): void {
  this.loadLbSelect()
if(this.optype == "update"){
  this.getGysByid();
}
}

getGysByid(){
  this.adminService.getGysByid(this.id).then((data:any)=>{
    if(data.msg == "ok"){
      this.g = data.obj
    }else{
      this.alertService.showError("根据id获取供应商失败")
    }
  })
}

  loadLbSelect(){
  this.adminService.getNzSelCateByTypeid("root").then((data:any)=>{
    if(data.msg == "ok"){
      this.lbArray = data.list
    }else{
      this.alertService.showError("获取供应商类别失败")
    }
  })
}

  save(){
    this.adminService.saveGys(this.g).then((data:any)=>{
      if(data.msg == "ok"){
        this.alertService.showSuccess("设置供应商成功")
      }else{
        this.alertService.showError("设置供应商失败")
      }
    })
  }

}
